package org.qfbl.c4;

import lombok.extern.slf4j.Slf4j;
import org.qfbl.utils.ByteBufferUtil;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;

@Slf4j
public class Server {
    public static void main(String[] args) throws IOException {
        // 1、创建了服务器
        ServerSocketChannel ssc  = ServerSocketChannel.open();

        ssc.configureBlocking(false) ;
        ssc.bind(new InetSocketAddress(8080));
        ByteBuffer buffer = ByteBuffer.allocate(16);
        List<SocketChannel> channels = new ArrayList<>() ;
        while (true){
            // 3、accept 建立与客户端的连接，SocketChannel用来与客户端之间通信
            log.info("开始接入连接。。。");
            SocketChannel accept = ssc.accept();
            log.info("已经接入连接。。。：{}",accept );
//            channels.add(accept);
//            for (SocketChannel channel : channels) {
//                channel.read(buffer);
//                buffer.flip() ;
//                ByteBufferUtil.debugAll(buffer);
//                buffer.clear() ;
//            }


        }
    }
}
